import {requestService} from '/src/utils/request'
import {getRefreshToken} from '/src/utils/auth'

// 登录方法
export function login(client_id, client_secret, username, password, grant_type) {
    const data = {
        client_id,
        client_secret,
        username,
        password,
        grant_type,
        tenant_id: 0
    }
    return requestService({
        url: '/xiaozhen-auth/oauth/token',
        method: 'post',
        data: data,
        transformRequest: [function (data) {
            let ret = ''
            for (let it in data) {
                ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
            }
            return ret
        }]
    })
}


//获取个人信息（登录权限验证）
export function getInfo() {
    return requestService({
        url: '/xiaozhen-system/sysUser/getInfo',
        method: 'get'
    })
}


// 获取路由
export function getRouters() {
    return requestService({
        url: '/xiaozhen-system/sysMenu/getRouters',
        method: 'get'
    })
}

//无感知刷新token
export function getNewToken() {
    const refreshToken = getRefreshToken();
    const data = {
        grant_type: "refresh_token",
        client_id: "app",
        client_secret: "123456",
        refresh_token: refreshToken,
    }
    return requestService({
        url: '/xiaozhen-auth/oauth/token',
        method: 'post',
        data: data,
        transformRequest: [function (data) {
            let ret = ''
            for (let it in data) {
                ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
            }
            return ret
        }]
    })
}
